<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const arr = [
        {
          id: '1195268474480156673',
          pid: '1',
          level: 1,
          children: [
            {
              id: '1195268616021139457',
              pid: '1195268474480156673',
              level: 2,
              children: [
                {
                  id: '1195269143060602882',
                  pid: '1195268616021139457',
                  level: 3,
                  children: [],
                  select: false,
                  name: '查看',
                  type: '2',
                  permissionValue: 'user.list',
                  path: null,
                  component: null,
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                },
                {
                  id: '1195269295926206466',
                  pid: '1195268616021139457',
                  level: 3,
                  children: [],
                  select: false,
                  name: '添加',
                  type: '2',
                  permissionValue: 'user.add',
                  path: 'user/add',
                  component: 'acl/user/form',
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                },
                {
                  id: '1195269473479483394',
                  pid: '1195268616021139457',
                  level: 3,
                  children: [],
                  select: false,
                  name: '修改',
                  type: '2',
                  permissionValue: 'user.update',
                  path: 'user/update/:id',
                  component: 'acl/user/form',
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                },
                {
                  id: '1195269547269873666',
                  pid: '1195268616021139457',
                  level: 3,
                  children: [],
                  select: false,
                  name: '删除',
                  type: '2',
                  permissionValue: 'user.remove',
                  path: null,
                  component: null,
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                }
              ],
              select: false,
              name: '用户管理',
              type: '1',
              permissionValue: null,
              path: 'user/list',
              component: 'acl/user/list',
              icon: null,
              status: 1,
              isDeleted: 0,
              createTime: '2022-07-28 20:00:00',
              modifyTime: null
            },
            {
              id: '1195268788138598401',
              pid: '1195268474480156673',
              level: 2,
              children: [
                {
                  id: '1195269821262782465',
                  pid: '1195268788138598401',
                  level: 3,
                  children: [],
                  select: false,
                  name: '修改',
                  type: '2',
                  permissionValue: 'role.update',
                  path: 'role/update/:id',
                  component: 'acl/role/form',
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                },
                {
                  id: '1195269903542444034',
                  pid: '1195268788138598401',
                  level: 3,
                  children: [],
                  select: false,
                  name: '查看',
                  type: '2',
                  permissionValue: 'role.list',
                  path: null,
                  component: null,
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                },
                {
                  id: '1195270037005197313',
                  pid: '1195268788138598401',
                  level: 3,
                  children: [],
                  select: false,
                  name: '添加',
                  type: '2',
                  permissionValue: 'role.add',
                  path: 'role/add',
                  component: 'acl/role/form',
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                },
                {
                  id: '1195270442602782721',
                  pid: '1195268788138598401',
                  level: 3,
                  children: [],
                  select: false,
                  name: '删除',
                  type: '2',
                  permissionValue: 'role.remove',
                  path: null,
                  component: null,
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                },
                {
                  id: '1195270621548568578',
                  pid: '1195268788138598401',
                  level: 3,
                  children: [],
                  select: false,
                  name: '角色权限',
                  type: '2',
                  permissionValue: 'role.acl',
                  path: 'role/distribution/:id',
                  component: 'acl/role/roleForm',
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                }
              ],
              select: false,
              name: '角色管理',
              type: '1',
              permissionValue: null,
              path: 'role/list',
              component: 'acl/role/list',
              icon: null,
              status: 1,
              isDeleted: 0,
              createTime: '2022-07-28 20:00:00',
              modifyTime: null
            },
            {
              id: '1195268893830864898',
              pid: '1195268474480156673',
              level: 2,
              children: [
                {
                  id: '1195270744097742849',
                  pid: '1195268893830864898',
                  level: 3,
                  children: [],
                  select: false,
                  name: '查看',
                  type: '2',
                  permissionValue: 'permission.list',
                  path: null,
                  component: null,
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                },
                {
                  id: '1195270810560684034',
                  pid: '1195268893830864898',
                  level: 3,
                  children: [],
                  select: false,
                  name: '添加',
                  type: '2',
                  permissionValue: 'permission.add',
                  path: null,
                  component: null,
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                },
                {
                  id: '1195270862100291586',
                  pid: '1195268893830864898',
                  level: 3,
                  children: [],
                  select: false,
                  name: '修改',
                  type: '2',
                  permissionValue: 'permission.update',
                  path: null,
                  component: null,
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                },
                {
                  id: '1195270887933009922',
                  pid: '1195268893830864898',
                  level: 3,
                  children: [],
                  select: false,
                  name: '删除',
                  type: '2',
                  permissionValue: 'permission.remove',
                  path: null,
                  component: null,
                  icon: null,
                  status: 1,
                  isDeleted: 0,
                  createTime: '2022-07-28 20:00:00',
                  modifyTime: null
                }
              ],
              select: false,
              name: '菜单管理',
              type: '1',
              permissionValue: null,
              path: 'menu/list',
              component: 'acl/menu/list',
              icon: null,
              status: 1,
              isDeleted: 0,
              createTime: '2022-07-28 20:00:00',
              modifyTime: null
            }
          ],
          select: false,
          name: '权限管理',
          type: '1',
          permissionValue: null,
          path: '/acl',
          component: 'Layout',
          icon: null,
          status: 1,
          isDeleted: 0,
          createTime: '2022-07-28 20:00:00',
          modifyTime: null
        },
        {
          id: '1557993400208674817',
          pid: '1',
          level: 1,
          children: [
            {
              id: '1557994388042764290',
              pid: '1557993400208674817',
              level: 2,
              children: [],
              select: true,
              name: '信息管理',
              type: '1',
              permissionValue: 'person.infoManager',
              path: 'person/infoManager',
              component: 'account/person/infoManager',
              icon: null,
              status: 1,
              isDeleted: 0,
              createTime: '2022-08-12 15:36:22',
              modifyTime: '2022-08-12 19:50:35'
            }
          ],
          select: true,
          name: '个人中心',
          type: '1',
          permissionValue: 'person',
          path: '/account',
          component: 'Layout',
          icon: null,
          status: 1,
          isDeleted: 0,
          createTime: '2022-08-12 15:32:27',
          modifyTime: null
        }
      ]

      const finalRes = []
      function test(arr) {
        arr.forEach((item) => {
          if (item.select && item.children.length == 0) {
            finalRes.push(item.id)
          } else if (item.children && item.children.length) {
            test(item.children)
          }
        })
        return finalRes
      }

      const res = test(arr)
      console.log(res)
    </script>
  </body>
</html>
